﻿@{
    Layout = null;
}
@model Freshbox2._0.MODEL.marketstoreinfo
<!DOCTYPE html>

<html>
<head>
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="icon" type="image/gif" href="~/img/animated_favicon1.gif">
    <meta name="viewport" content="width=device-width" />
    <link href="~/UILibs/easyui/themes/default/easyui.css" rel="stylesheet" />
    <link href="~/UILibs/easyui/themes/icon.css" rel="stylesheet" />
    <link href="~/Css/css.css" rel="stylesheet" />

    <script src="~/Scripts/jquery-1.7.1.min.js"></script>
    <script src="~/UILibs/easyui/jquery.easyui.min.js"></script>
    <script src="~/UILibs/easyui/locale/easyui-lang-zh_CN.js"></script>

    <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
    <title></title>
    <script type="text/javascript">
        //时间格式化 转化为 yyyy
        function format(str) {
            if (str != null) {
                var d = eval('new ' + str.substr(1, str.length - 2));
                var ar_date = [d.getFullYear(), d.getMonth() + 1, d.getDate()];
                for (var i = 0; i < ar_date.length; i++) ar_date[i] = dFormat(ar_date[i]);
                return ar_date.join('-');
                function dFormat(i) { return i < 10 ? "0" + i.toString() : i; }
            }
            else {
                return null;
            }
        }

        //判断手机号码是否正确
        function checkSubmitMobil1() {
            var reg = /(1[3-9]\d{9}$)/;
            if ($("#contactorPhone").val() != null) {
                if (!reg.test($("#decidePhone").val())) {
                    $.messager.alert("警告", "企业决策人手机号码格式不正确")
                }
            }
        }

        function checkSubmitMobil2() {
            var reg = /(1[3-9]\d{9}$)/;
            if ($("#contactorPhone").val() != null) {
                if (!reg.test($("#contactorPhone").val())) {
                    $.messager.alert("警告", "企业对接人手机号码格式不正确")
                }
            }
        }

        $(function () {
            $("#data").datagrid({
                fit: true,
                title: '有意向公司信息统计',
                striped: true,
                rownumbers: true,
                columns:
                    [[{
                        field: 'ck',
                        checkbox: true
                    }, {
                        field: 'marketStoreID',
                        title: '编号',
                        width: 80,
                        height: 50,
                        halign: 'center',
                        sortable: true,
                        align: 'center'
                    }, {
                        field: 'marketState',
                        title: '当前状态',
                        width: 180,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    }, {
                        field: 'fillDate',
                        title: '填表日期',
                        width: 150,
                        height: 50,
                        halign: 'center',
                        align: 'center',
                        formatter: format
                    }, {
                        field: 'value1',
                        title: '市场人员姓名',
                        width: 120,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    },
                    //{
                    //    field: 'decidePhone',
                    //    title: 'BD联系方式',
                    //    width: 150,
                    //    height: 50,
                    //    halign: 'center',
                    //    sortable: true,
                    //    align: 'center'
                    //},
                    {
                        field: 'businessContactor',
                        title: '企业对接人',
                        width: 120,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    }, {
                        field: 'contactorPhone',
                        title: '对接人联系方式',
                        width: 150,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    }, {
                        field: 'companyName',
                        title: '企业名称',
                        width: 250,
                        height: 50,
                        halign: 'center',
                        align: 'center',
                    }, {
                        //companyAddress  companySize  companyType  planPutTime actuallyPutTime marketState  value1
                        field: 'companyAddress',
                        title: '企业地址',
                        width: 350,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    },
                    //{
                    //    field: 'companySize',
                    //    title: '企业规模',
                    //    width: 80,
                    //    height: 50,
                    //    halign: 'center',
                    //    align: 'center'
                    //}, {
                    //    field: 'companyType',
                    //    title: '企业性质',
                    //    width: 100,
                    //    height: 50,
                    //    halign: 'center',
                    //    align: 'center'
                    //},
                    //{
                    //    field: 'planPutTime',
                    //    title: '计划投放时间',
                    //    width: 120,
                    //    height: 50,
                    //    halign: 'center',
                    //    align: 'center',
                    //    formatter: format
                    //}, {
                    //    field: 'actuallyPutTime',
                    //    title: '实际投放时间',
                    //    width: 120,
                    //    height: 50,
                    //    halign: 'center',
                    //    align: 'center',
                    //    formatter: format
                    //},
                    {
                        field: 'value2',
                        title: '备注',
                        width: 280,
                        height: 50,
                        halign: 'center',
                        align: 'center',

                    }
                    ]],
                url: pageConfig.getAction,
                pagination: true,
                pageSize: 25,
                pageList: [25, 30, 35],
                sortName: 'marketStoreID',
                sortOrder: 'desc',
                toolbar: '#tool'
            });
            $("#formdialog").dialog({
                width: 470,
                height: 450,
                closed: true,
                modal: true,
                buttons: '#btns'
            });
        });
        var pageConfig = {
            type: null,
            getAction: '@Url.Action("Get")',
            saveAction: '@Url.Action("Save")',
            delAction: '@Url.Action("Delete")',
            modifyAction: '@Url.Action("Modify")',
            getOneAction: '@Url.Action("GetOnlyOne")',
        };
        ///禁用用户   状态改变
        function del() {

            var rows = $("#data").datagrid("getSelections")
            if (rows.length <= 0) {
                $.messager.alert("禁用用户", "没有选中的行", "info");
                return;
            }

            $.messager.confirm("确定操作", "您确定要删除该信息吗？", function (flag) {
                if (flag) {
                    var idsStr = rows[0].marketStoreID;
                    $.ajax({
                        url: pageConfig.delAction,
                        data: { id: idsStr },
                        dataType: "json",
                        type: "POST",
                        beforeSend: function () {
                            before();
                        },
                        success: function (data) {
                            success(data);
                        },
                        error: function () {
                            error();
                        },
                        complete: function () {
                            complete();
                        }
                    });
                }
            })
        }
        //弹出框
        function alertFormDialog(type) {
            pageConfig.type = type;
            $("#formdialog form").form("reset");
            if (type == 1) {
                $("#formdialog").dialog("open");
                $("#formdialog").dialog("setTitle", "添加");
                $("#formdialog form").attr("action", pageConfig.saveAction);
            }
            else {
                var rows = $("#data").datagrid("getSelections");

                if (rows.length != 1) {
                    $.messager.alert("提示", "修改时必须且只能选中一条记录！", "info");
                }
                if (rows[0].state == 1) {
                    $.messager.alert("提示", "此用户已经被禁用！不能进行修改", "info");
                }
                else {

                    $("#formdialog").dialog("open");
                    $("#formdialog").dialog("setTitle", "修改");
                    $('#adminUsername').attr("disabled", true);//不可编辑
                    $.ajax({
                        async: false,
                        url: pageConfig.getOneAction + "?id=" + rows[0].marketStoreID,
                        dataType: "json",
                        type: "POST",
                        success: function (data) {
                            //alert(data.value2);
                            $("#formdialog input[name='marketStoreID']").val(data.marketStoreID);
                            $('#fillDate').datebox('setValue', format(data.fillDate));
                            $("#businessContactor").val(data.businessContactor);
                            $("#contactorPhone").val(data.contactorPhone);
                            // $("#businessDecide").val(data.businessDecide);
                            // $("#decidePhone").val(data.decidePhone);
                            $("#companyName").val(data.companyName);
                            $("#companyAddress").val(data.companyAddress);
                            //$("#companySize").val(data.companySize);
                            //$("#companyType").val(data.companyType);
                            //$('#planPutTime').datebox('setValue', format(data.planPutTime));
                            //$('#actuallyPutTime').datebox('setValue', format(data.actuallyPutTime));
                            $("#marketState").combobox('setValue', data.marketState);
                            $("#marketState").combobox('setValue', data.marketStateID);
                            $("#value1").val(data.value1);
                            $("#value2").textbox("setValue", data.value2);
                        }

                    });
                }
            }
        }

        function closeDptDialog() {
            $("#formdialog").dialog("close")
        }
        //点击保存按钮   
        function save() {
            var bool = $("#fm").form("validate");
            if (bool) {
                var rows = $("#data").datagrid("getSelections");
                var data;
                if (pageConfig.type == 1) {
                    url = pageConfig.saveAction;
                    data = {
                        //marketStoreID 海子  fillDate  businessContactor  contactorPhone  businessDecide  decidePhone companyName
                        //companyAddress  companySize  companyType  planPutTime actuallyPutTime marketState  value1
                        marketStoreID: $("#formdialog input[name='marketStoreID']").val(),
                        fillDate: $("#fillDate").val(),
                        businessContactor: $("#businessContactor").val(),
                        contactorPhone: $("#contactorPhone").val(),
                        //  businessDecide: $("#businessDecide").val(),
                        // decidePhone: $("#decidePhone").val(),
                        companyName: $("#companyName").val(),
                        companyAddress: $("#companyAddress").val(),
                        //companySize: $("#companySize").val(),
                        //companyType: $("#companyType").val(),
                        //planPutTime: $("#planPutTime").val(),
                        //actuallyPutTime: $("#actuallyPutTime").val(),
                        marketState: $("#marketState").val(),
                        value1: $("#value1").val(),
                        value2: $("#value2").val()
                    };
                }
                else {
                    // alert($("#marketState").combobox('getValue'));//未投放
                    //alert($("#marketState").val());
                    url = pageConfig.modifyAction;
                    data = {
                        marketStoreID: $("#formdialog input[name='marketStoreID']").val(),
                        fillDate: $("#fillDate").val(),
                        businessContactor: $("#businessContactor").val(),
                        contactorPhone: $("#contactorPhone").val(),
                        // businessDecide: $("#businessDecide").val(),
                        //decidePhone: $("#decidePhone").val(),
                        companyName: $("#companyName").val(),
                        companyAddress: $("#companyAddress").val(),
                        //companySize: $("#companySize").val(),
                        //companyType: $("#companyType").val(),
                        //planPutTime: $("#planPutTime").val(),
                        //actuallyPutTime: $("#actuallyPutTime").val(),
                        businessContactor: $("#businessContactor").val(),
                        marketState: $("#marketState").val(),
                        value1: $("#value1").val(),
                        value2: $("#value2").val()
                    };
                }
                $.ajax({
                    url: url,
                    dataType: "json",
                    data: data,
                    type: "POST",
                    beforeSend: function () {
                        $.messager.progress({ title: "执行中", text: "" });
                    },
                    success: function (data) {
                        $.messager.alert("成功", data.msg, "info");
                    },
                    error: function (data) {
                        $.messager.alert("警告", "系统故障", "error", "")
                    },
                    complete: function () {

                        complete();
                    }
                });

            }
        }

        function searchData() {
            $("#data").datagrid('load', {
                value1: $("#txtName").val(),
                marketState: $("#SmarketState").val()
            });
        }

        function before() {
            $.messager.progress({ title: "执行中", text: "" });
        }

        function success(data) {
            $.messager.alert("成功", data.msg, "info");
        }
        function error() {
            $.messager.alert("警告", "系统故障", "error", "")
        }

        function complete() {
            $("#data").datagrid("load");
            $.messager.progress("close");
            $("#formdialog").dialog("close");
        }

    </script>
</head>
<body class="easyui-layout" style="width: 100%; height: 100%">
    <div data-options="region:'center'">
        <table id="data"></table>
        <div id="tool" style="padding: 10px;">
            <div style="margin-bottom: 10px;">
                <div style="margin-bottom: 10px;">
                    &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                    <a class="easyui-linkbutton" iconcls="icon-add" style="width: 150px; height: 50px;" onclick="alertFormDialog(1)">添加点位信息</a> &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                    <a class="easyui-linkbutton" iconcls="icon-edit" style="width: 150px; height: 50px;" onclick="alertFormDialog(2)">修改点位信息</a> &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                    <a class="easyui-linkbutton" iconcls="icon-remove" style="width: 150px; height: 50px;" onclick="del()">删除点位信息</a>
                    &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp
                   市场BD：<input id="txtName" style="width: 180px; height: 20px; margin-top: 13px" oninput="searchData()" />
                    &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                点位状态：
                        <select class="easyui-combobox" id="SmarketState" style="height: 25px; width: 180px" oninput="searchData()">
                             <option value="">请选择</option>
                            <option value="1">已投放</option>                           
                            <option value="0">未投放（未审核通过）</option>
                            <option value="3">未投放（暂未审核）</option>
                            <option value="2">已撤架</option>
                        </select>
                    &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                      <a class="easyui-linkbutton" iconcls="icon-search" onclick="searchData()">查询</a>
                </div>
            </div>
        </div>
    </div>

    <div id="formdialog">
        @using (Ajax.BeginForm(new AjaxOptions
        {
            OnBegin = "before",
            OnComplete = "complete",
            OnSuccess = "success",
            OnFailure = "error",
            HttpMethod = "Post"
        }))
        {
            <div class="dialog-table">
                <form id="fm" method="post">
                    @*//marketStoreID   fillDate  businessContactor  contactorPhone  businessDecide  decidePhone companyName  *@

                    @Html.HiddenFor(x => x.marketStoreID)

                    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tk_table">
                        <tr>
                            <td style="text-align: center">填表日期：</td>
                            <td class="white-tr">
                                <input class="easyui-datebox" id="fillDate" style="height: 23px; width: 200px" data-options="required:true" /></td>
                        </tr>
                        <tr>
                            <td style="text-align: center">市场经理姓名：</td>
                            <td class="white-tr">
                                <input class="easyui-validatebox" id="value1" style="height: 22px; width: 200px" data-options="required:true" /></td>
                        </tr>
                        @*                     <tr>
                            <td>BD联系方式：</td>
                            <td class="white-tr">
                                <input class="easyui-validatebox" id="decidePhone"  onchange="checkSubmitMobil1()"/></td>
                           
                        </tr>*@
                        <tr>
                            <td style="text-align: center">企业对接人：</td>
                            <td class="white-tr">
                                <input class="easyui-validatebox" style="height: 22px; width: 200px" id="businessContactor" /></td>
                        </tr>
                        <tr>
                            <td style="text-align: center">对接人联系方式：</td>
                            <td class="white-tr">
                                @* onchange="checkSubmitMobil2()  " *@
                                <input class="easyui-validatebox" style="height: 22px; width: 200px" id="contactorPhone" /></td>
                        </tr>
                        @*                 <tr>
                            <td>企业决策人：</td>
                            <td class="white-tr">
                                <input class="easyui-validatebox" id="businessDecide" /></td>
                        </tr>*@
                        <tr>
                            <td style="text-align: center">公司名称：</td>
                            <td class="white-tr">
                                <input class="easyui-validatebox" id="companyName" style="height: 22px; width: 200px" data-options="required:true" /></td>
                        </tr>
                        <tr>
                            @* //companyAddress  companySize  companyType  planPutTime actuallyPutTime marketState  value1*@
                            <td style="text-align: center">企业地址：</td>
                            <td class="white-tr">
                                <input class="easyui-validatebox" id="companyAddress" style="height: 22px; width: 200px" data-options="required:true" /></td>
                        </tr>
                        @*  <tr>
                            <td>企业规模：</td>
                            <td class="white-tr">
                                <input class="easyui-validatebox" id="companySize" data-options="required:true" /></td>
                        </tr>
                        <tr>
                            <td>企业性质：</td>
                            <td class="white-tr">
                                <input class="easyui-validatebox" id="companyType" /></td>
                        </tr>
                        <tr>
                            <td>计划投放时间：</td>
                            <td class="white-tr">
                                <input class="easyui-datebox" id="planPutTime" /></td>
                        </tr>
                        <tr>
                            <td>实际投放时间：</td>
                            <td class="white-tr">
                                <input class="easyui-datebox" id="actuallyPutTime" /></td>
                        </tr>*@
                        <tr>
                            <td style="text-align: center">点位状态：</td>
                            <td class="white-tr">
                                <select class="easyui-combobox" id="marketState" style="height: 25px; width: 200px">
                                    <option value="1">已投放</option>
                                    <option value="0">未投放（未审核通过）</option>
                                    <option value="3">未投放（暂未审核）</option>
                                    <option value="2">已撤架</option>
                                </select>
                        </tr>
                        <tr>
                            <td style="text-align: center">备注：</td>
                            <td class="white-tr">
                                <input class="easyui-textbox" data-options="multiline:true" style="height: 40px; width: 200px" id="value2" /></td>
                        </tr>

                    </table>
                </form>
            </div>
        }
    </div>

    <div id="btns">
        <div style="margin-bottom: 10px">
            <a class="easyui-linkbutton" iconcls="icon-redo" onclick="closeDptDialog()">取消</a>
            <a class="easyui-linkbutton" iconcls="icon-add" onclick="save()">保存</a>
        </div>
    </div>

</body>
</html>
